package com.qf.controller;

import com.qf.dto.HouseDto;
import com.qf.entity.House;
import com.qf.result.ResponseResult;
import com.qf.service.HouseService;
import com.qf.utils.BeanCopyUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@RestController
@RequestMapping("/house")
@Api(tags = "房屋管理", description = "房屋管理相关接口")
public class HouseController {

    @Autowired
    private HouseService houseService;

    @GetMapping("/getHouseList")
    @ApiOperation(value = "房屋列表", notes = "获取所有房屋列表")
    public ResponseResult getHouseList() {
        return houseService.getHouseList();
    }

    @PostMapping("/addHouse")
    @ApiOperation(value = "添加房屋", notes = "添加房屋信息")
    public ResponseResult addHouse(@Valid @RequestBody HouseDto houseDto) {
        return houseService.addHouse(BeanCopyUtils.copyBean(houseDto.setId(null), House.class));
    }

    @PutMapping("/updateHouse")
    @ApiOperation(value = "更新房屋", notes = "更新房屋信息")
    public ResponseResult updateHouse(@Valid @RequestBody HouseDto houseDto) {
        return houseService.updateHouse(BeanCopyUtils.copyBean(houseDto, House.class));
    }

    @DeleteMapping("/deleteHouse/{id}")
    @ApiOperation(value = "删除房屋", notes = "删除房屋信息")
    public ResponseResult deleteHouse(@PathVariable Integer id) {
        return houseService.deleteHouse(id);
    }

    //获取未分配业主的房屋列表
    @ApiOperation(value = "获取未分配的房屋")
    @GetMapping("/getHouseByFalseStatus")
    public ResponseResult getHouseByStatus() {
        return houseService.getHouseByStatus();
    }

    //获取分配业主的房屋列表
    @ApiOperation(value = "获取已分配的房屋")
    @GetMapping("/getHouseByTrueStatus")
    public ResponseResult getHouseByTrueStatus() {
        return houseService.getHouseByTrueStatus();
    }


}
